package com.example.JetpackDemoApp.ui.home.activities

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.annotation.IdRes
import com.example.JetpackDemoApp.R
import com.example.JetpackDemoApp.databinding.ActivityMaterialButtonToggleGroupBinding
import com.google.android.material.button.MaterialButton
import com.google.android.material.button.MaterialButtonToggleGroup

class MaterialButtonToggleGroupActivity : AppCompatActivity() {
    private lateinit var binding: ActivityMaterialButtonToggleGroupBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMaterialButtonToggleGroupBinding.inflate(layoutInflater)
        setContentView(binding.root)

        binding.materialSingleBtnGroup.addOnButtonCheckedListener(this::handleButtonGroup)
    }

    private fun handleButtonGroup(group: MaterialButtonToggleGroup, @IdRes checkedId: Int, isChecked: Boolean) {
        Log.e("checkedId===>", checkedId.toString())
        val checkedButton: MaterialButton = findViewById(checkedId)
        Log.e("isChecked===>${checkedButton.text}==>", isChecked.toString())
        if(isChecked) {
            when(checkedId) {
                R.id.material_button10 -> println("material_button10")
                R.id.material_button11 -> println("material_button11")
                R.id.material_button12 -> println("material_button12")
                R.id.material_button13 -> println("material_button13")
                else -> println("Nothing matched")
            }
        }
    }
}